using System;
using System.Web;
using System.Collections.Generic;
using System.Text;

using Essentials.Persistence.Connection;
using Essentials.Persistence.Info;

namespace Essentials.Environment
{
    public class Env
    {

		public static void Create(string dbName)
		{
			// Creo la conexion con la base de datos.
			Conn.Create(dbName);

			User.EvGetUserData += new User.GetUserInfo(GetUserName);

			User.EvGetUserMachineName += new User.GetUserInfo(GetUserMachineName);

			User.EvGetUserSessionName += new User.GetUserInfo(GetUserSessionName);
		}

        public static void Create()
        {
            Create(null, null, null);
        }

        public static void Create(User.GetUserInfo getUserData, User.GetUserInfo getMachineName, User.GetUserInfo getUserSessionName)
        {            
            // Creo la conexion con la base de datos.
            Conn.Create();

            if (getUserData == null)
                User.EvGetUserData += new User.GetUserInfo(GetUserName);
            else
                User.EvGetUserData += new User.GetUserInfo(getUserData);

            if (getMachineName == null)
                User.EvGetUserMachineName += new User.GetUserInfo(GetUserMachineName);
            else
                User.EvGetUserMachineName += new User.GetUserInfo(getMachineName);

            if (getUserSessionName == null)
                User.EvGetUserSessionName += new User.GetUserInfo(GetUserSessionName);
            else
                User.EvGetUserSessionName += new User.GetUserInfo(getUserSessionName);

        }

        /// <summary>
        /// Sobreescribirla si se quiere retornar otro usuario
        /// </summary>
        /// <returns></returns>
        public static string GetUserName()
        {
            return System.Environment.UserDomainName + "\\" + System.Environment.UserName;
        }

        public static string GetUserMachineName()
        {
            return System.Environment.MachineName;
        }

        public static string GetUserSessionName()
        {
            return "";
        }

    }
}
